package com.uenpay.im.ui.old.activity.remark;

import com.qiyunxin.android.http.net.HttpRequestType;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.im.invokeitems.HttpRequestHandle;

/**
 * @author SL
 * @created 2016-1-19 下午2:40:36
 * @copyRight http://www.qiyunxin.com
 * @function 备注管理类
 */
public class RemarkHandle {

	public interface ISetRemarkResultListener {
		void setRemarkResult(int status, String msg);
	};

	/**
	 * 设置备注
	 * 
	 * @param custid
	 * @param nickName
	 * @param phoneNums
	 * @param memo
	 * @param mISetRemarkResultListener
	 */
	public void setRemark(final String custid, String nickName,
			String phoneNums, String memo,
			final ISetRemarkResultListener mISetRemarkResultListener) {
		SetFriendMemoInvokeItem item = new SetFriendMemoInvokeItem(custid,
				nickName, phoneNums, memo);
		HttpRequestHandle.onBaseRequest(item, HttpRequestType.SERVER_ONLY,
				new HttpRequestHandle.IRequestResultListener() {

					@Override
					public void onResult(Object resultObject, boolean isCache,
							String failReason) {
						if (resultObject != null) {
							final SetFriendMemoInvokeItem.SetFriendMemoInvokeItemResult result = ((SetFriendMemoInvokeItem) resultObject)
									.getOutPut();
							if (result != null) {
								mISetRemarkResultListener.setRemarkResult(
										result.status, result.msg);
							} else {
								mISetRemarkResultListener.setRemarkResult(-1,
										failReason);
							}
						} else {

							mISetRemarkResultListener.setRemarkResult(-1,
									failReason);

						}
					}
				});
	}

	public interface IGetRemarkResultListener {
		void onGetRemarkResult(int status, String msg,
											   QYXUserEntity mQyxUserEntity);
	}

	/**
	 * 获取好友备注信息
	 * 
	 * @param custid
	 * @param mIGetRemarkResultListener
	 */
	public void getRemark(final String custid,
			final IGetRemarkResultListener mIGetRemarkResultListener) {
		GetFriendMemoInvokeItem item = new GetFriendMemoInvokeItem(custid);

		HttpRequestHandle.onBaseRequest(item,
				HttpRequestType.SERVER_FAIL_AND_CACHE,
				new HttpRequestHandle.IRequestResultListener() {

					@Override
					public void onResult(Object resultObject, boolean isCache,
										 String failReason) {
						if (resultObject != null) {
							final GetFriendMemoInvokeItem.GetFriendMemoInvokeItemResult result = ((GetFriendMemoInvokeItem) resultObject)
									.getOutPut();
							if (result != null) {
								mIGetRemarkResultListener.onGetRemarkResult(
										result.status, result.msg,
										result.qyxUserEntity);
							} else {
								mIGetRemarkResultListener.onGetRemarkResult(-1,
										failReason, null);
							}
						} else {
							mIGetRemarkResultListener.onGetRemarkResult(-1,
									failReason, null);
						}
					}
				});
	}
}